package com.baichang.taoshunda.controller.mobile.business;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.BussMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(ControllerConstants.BUSSINESSMSG)
public class BussinessMsgMController extends BaseMobileController {

    @Autowired
    private BussMsgService bussMsgService;

    /**
     * 获取登录时候的验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getLoginMsg")
    public void getLoginMsg(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                String mobile = getString(json, "mobile", "");
                return bussMsgService.getLoginMsg(mobile);
            }
        });
    }

    /**
     * 验证验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/checkCodeMsg")
    public void checkCodeMsg(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                String phone = getString(json, "phone", "");
                String code = getString(json, "code", "");
                return bussMsgService.checkCodeMsg(phone, code);
            }
        });
    }

    /**
     * 获取注册时候的验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getRegisterMsg")
    public void getRegisterMsg(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                String mobile = getString(json, "mobile", "");
                return bussMsgService.getRegisterMsg(mobile);
            }
        });
    }

    /**
     * 获取忘记密码时候的验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getForgetPwdMsg")
    public void getForgetPwdMsg(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                String mobile = getString(json, "mobile", "");
                return bussMsgService.getForgetPwdMsg(mobile);
            }
        });
    }

    /**
     * 获取绑定银行卡时候的验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getBindBankCardMsg")
    public void getBindBankCardMsg(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                String mobile = getString(json, "mobile", "");
                return bussMsgService.getBindBankCardMsg(mobile);
            }
        });
    }


    /**
     * 提现时候的验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getCashMsg")
    public void getCashMsg(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String json) throws ServiceException {
                String mobile = getString(json, "mobile", "");
                Double money = getDouble(json, "money", 0D);
                return bussMsgService.getCashMsg(mobile, money);
            }
        });
    }


}
